/*
 * @Author: zxc
 * @Date: 2020-07-31 14:07:20
 * @LastEditTime: 2020-08-14 11:58:24
 * @LastEditors: zxc
 * @Description: 接口
 */ 
interface NameInfo {
  firstName:string,
  lastName:string
}
const getFullName = ({firstName,lastName}:NameInfo):string => {
  return `${firstName} ${lastName}`
} 

console.log(getFullName({
  firstName:'kk',
  lastName:'bb'
}))

interface Vegetable {
  colors?:string,
  readonly type:string,
  [prop:string]:any
}
const getVegetable = ({colors,type}:Vegetable):string => {
  return `a${colors ? (colors + ' ') : " "} ${type}`
} 
// console.log(getVegetable({
//   // colors:'red',
//   type:'tomato' 
// })) 

// console.log(getVegetable({
//   // colors:'red',
//   type:'tomato' 
// } as IVegetable)) 


interface ArrInter{
  0:number,
  readonly 1:string,
  [props:number]:any
}
let arr:ArrInter = [1,'a',123,42,243.23]
// arr[1] = '234'

type AddFunc = (num1:number,num2:number)  => number

const add:AddFunc = (n1,n2) => n1+n2
console.log(add(1,2))

interface RoleDic{
  [id:string]:string
}

const role1:RoleDic = {
  1:"super",
  a:'public'
}
console.log(role1)


interface Veges {
  color:string
}
interface Tam extends Veges {
  radius:number
}

interface Cars extends Veges {
  length:string
}

const newTam:Tam = {
  color:'red',
  radius:2
}

interface Counters{
  ():void,
  count:number
}
const getCounter = ():Counters => {
  const c = () => {c.count++}
  c.count = 0;
  return c
}

const counter:Counters = getCounter()
counter()
console.log(counter.count)
counter()
console.log(counter.count)
counter()
console.log(counter.count)
counter()
console.log(counter.count)
counter()
console.log(counter.count)